<%@ page language="java" contentType="text/html; charset=UTF-8"  import="java.sql.*" pageEncoding="UTF-8"%>
<%@ page import="DbUtil.JdbcUtils" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<script type="text/javascript">  
      function exportExcel(){  
          window.open('testExcel.jsp?exportToExcel=YES');  
      }  
 </script>
<head>
<link rel="stylesheet" type="text/css" href="css/shoppingcart.css">
<!-- 显示网格线 -->
<xml>    
                <x:ExcelWorkbook>    
                    <x:ExcelWorksheets>    
                        <x:ExcelWorksheet>    
                            <!-- <x:Name>工作表标题</x:Name>-->  
                            <x:WorksheetOptions>    
                                <x:Print>    
                                    <x:ValidPrinterInfo />    
                                </x:Print>    
                            </x:WorksheetOptions>    
                        </x:ExcelWorksheet>    
                    </x:ExcelWorksheets>    
                </x:ExcelWorkbook>    
            </xml>
<!-- 显示网格线 -->
<script type="text/javascript">
	function excelsuccess(){
		alert("导出成功!");
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>导出Excel表</title>
</head>
<body> 
    <center>
 <%
	java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	java.util.Date currentTime = new java.util.Date();
	String time = formatter.format(currentTime); 
	System.out.println(time);
	String exportToExcel = request.getParameter("exportToExcel");
	if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) {
	response.setContentType("application/vnd.ms-excel");
	response.setHeader("Content-Disposition", "inline; filename="+"order.xls");
}
%>           

<%
		
		request.setCharacterEncoding("utf-8");
		Connection conn=JdbcUtils.getConnection();
		String sql="select * from studentlist where regist='是'";
		
		Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
		ResultSet rs = stmt.executeQuery(sql);
		rs.last();
		int countall=rs.getRow();
		rs.beforeFirst();
		if(rs.next()&&countall!=0)
		{
			out.println("<table border='1' cellspacing='0' bordercolor='#000000' width = '80%'style='border-collapse:collapse;' class='zong'>");
			out.println("<tr style='text-align:center' id='biaotou'>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>学生学号</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>学生姓名</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>性别</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>班别</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>楼栋</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>宿舍号</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>晚归原因</th>");
			out.println("<th style='text-align:center' class='text-center' width=180px; scope='col'>是否被登记</th>");
			out.println("</tr>");
		do{
			out.println("<tr bgcolor='#ffffff' id='biaoge'>");
			out.println("<td style=text-align:center>"+rs.getString("studentNo")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("studentName")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("sex")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("className")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("dormName")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("roomNo")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("lateReason")+"</td>");
			out.println("<td style=text-align:center>"+rs.getString("regist")+"</td>");
			out.println("</tr>");
		}while(rs.next());
			out.println("</table>");
		}
		else
		{
			out.println("<p>还没有请假表，赶紧填写吧！！！</p>");
		}
			stmt.close();
			conn.close();
		%>
		<%
		if (exportToExcel == null) {
		%>  
		  <center><a href="javascript:exportExcel();" onclick="excelsuccess()">导出为Excel</a></center>
		  <%
		}
%>   </center> 
    </body>
</html>
